#open
import random

f=open("test.txt", "r", encoding="UTF-8")
print(type(f))
#read()
"""
test=f.read(2)
print(test)
print(type(test))
"""
#readlines
"""
line=f.readlines()
print(type(line))
print(line)
"""

#readline
"""
print(f.readline())
print(f.readline())
print(f.readline())
"""

#for 读取
print("=====for 读取=====")
for line in f:

    print(line.strip(),end="")
    print(" type:",type(line))


#文件关闭
f.close()

#with open
print("===with open 关闭===")
with open("test.txt", "r", encoding="UTF-8") as f:
    for line in f:
        #content=line.replace("\n","")
        content=line.strip()
        print(content)

print("===========文件写操作===========")
#模式：w、a
#wf=open("w_test.txt", "w", encoding="UTF-8")
wf=open("w_test.txt", "w", encoding="UTF-8")
wf.write("hellow1\n")
wf.write("hellow1\n")
wf.write("hellow1\n")
wf.flush()
wf.close()

with open("w_test.txt", "r", encoding="UTF-8") as f:
    print(f.readlines())

print(random.randint(1, 2))
for x in range(1,2):
    print(x)